package zust.study.设计模式.结构型模式.过滤器模式.api;

import zust.study.设计模式.结构型模式.过滤器模式.Person;

import java.util.List;

/**
 * @author senselyan
 * @date 2018/6/7 10:26
 */
public class OrCriteria implements Criteria {

    private Criteria criteria;
    private Criteria otherCriteria;

    public OrCriteria(Criteria criteria, Criteria otherCriteria) {
        this.criteria = criteria;
        this.otherCriteria = otherCriteria;
    }

    @Override
    public List<Person> meetCriteria(List<Person> people) {
        List<Person> first = criteria.meetCriteria(people);
        List<Person> second = otherCriteria.meetCriteria(people);
        for (Person per : first) {
            if (!second.contains(per)) {
                second.add(per);
            }
        }
        return second;
    }
}
